import Main from '../view/main/Main'

export const loginRouter = {
  path: '/login',
  name: 'login',
  meta: {
    title: 'Login - 登录',
    notNeedToken: true
  },
  component: resolve => {
    require(['@/view/acc/login/login.vue'], resolve)
  }
}

export const page404 = {
  path: '/*',
  name: 'error_404',
  meta: {
    title: '404-页面不存在',
    notNeedToken: true
  },
  component: resolve => {
    require(['@/view/error_page/404.vue'], resolve)
  }
}

const TopMenu = {
  home: '首页',
  system: '系统设置',
}

const HomeRouter = {
  title: TopMenu.home,
  icon: 'ios-home',
  routers: [
    {
      path: '/',
      icon: 'ios-home',
      meta: {title: '首页'},
      name: 'home',
      component: Main,
      children: [
        {
          path: 'home', meta: {title: '首页', parent: TopMenu.home}, name: 'home_index', component: resolve => {
            require(['@/view/main/index/home.vue'], resolve)
          }
        }
      ]
    }
  ]
}

export const SystemSetRouter = {
  title: TopMenu.system,
  icon: 'ios-home',
  routers: [{
    path: '/personalSet',
    icon: 'ios-home',
    meta: {title: '个人信息'},
    name: 'personalSet',
    component: Main,
    children: [
      {
        path: 'personInfo', meta: {title: '个人信息', parent: TopMenu.system}, name: 'personInfo', component: resolve => {
          require(['@/view/system/personalSet.vue'], resolve)
        }
      }
    ]
  }]
}

/**
 * 没有菜单的单页面在此设置
 * @type {{path: string, name: string, component: {name, data, components, computed, watch, methods, mounted}, children: Array}}
 */
export const otherRouter = {
  path: '/',
  name: 'otherRouter',
  component: Main,
  children: [
    { path: 'message',  meta: {title: '消息中心'}, name: 'message_index', component: resolve => { require(['@/view/message/message.vue'], resolve); } },
  ]
}

export const menuRouter = [HomeRouter,  SystemSetRouter]

/** 合并所有路由 **/
let menuList = []
menuRouter.map(item => {
  menuList = menuList.concat(...item.routers)
})
export {menuList}

export const routers = [
  ...menuList,
  otherRouter,
  loginRouter,
  page404
]

